﻿<html>
<head>
<title>JavaScript希尔排序</title>
</head>
<script>
	function shellsort(arr){  
		var len =arr.length;
		gap = Math.floor(len/2);
		while(gap!==0){
			for(var i = gap;i<len;i++){
				var temp = arr[i];
				var j;
				for(j=i-gap;j>=0&&temp<arr[j];j-=gap){
					arr[j+gap] = arr[j];
				}
				arr[j+gap] = temp;
			}
			
			console.log("间隔序列gap为"+gap+"："+arr.toString());
			gap=Math.floor(gap/2);
		}
	  return arr;
	}  
	var array = [59,34,25,67,15,87,10,99,3,45];
	var res_arr = shellsort(array);
	console.log("最终排序结果为："+res_arr.toString());
</script>
</html>


